package com.example.contentobserver;

import android.app.Activity;
import android.content.ContentResolver;
import android.database.ContentObserver;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;

public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ContentResolver resolver = getContentResolver();
        Uri uri = Uri.parse("content://com.yf.provider/insert");
		ContentObserver observer = new MyContentObserver(new Handler());
		// 参数二：false表示精确匹配；为true时仅匹配父级path即可，其下的所有子路径都可以匹配
		resolver.registerContentObserver(uri , false, observer );
    }
    
    private class MyContentObserver extends ContentObserver {

		public MyContentObserver(Handler handler) {
			super(handler);
		}
		
		@Override
		public void onChange(boolean selfChange, Uri uri) {
			super.onChange(selfChange);
			System.out.println(selfChange);
			System.out.println(uri);
		}
    }
}
